package demo;

/**
 * @Author liangbaigao
 * @Date 2023/9/24 22:52
 */
public class Lazy03 {

    /**
     * 双重校验
     */
    static class DoubleCheck{

        private DoubleCheck(){};

        private static volatile DoubleCheck instance;

        public static DoubleCheck getInstance(){
            if( instance == null){
                synchronized (DoubleCheck.class){
                    /*
                    这里是为了防止，线程刚刚释放锁资源，
                    其余线程进入判断获得锁资源加的校验
                     */
                    if(instance == null){
                        instance = new DoubleCheck();
                    }
                }
            }
            return instance;
        }
    }
}
